package org.example.practicaltraining.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.example.practicaltraining.commom.Result;
import org.example.practicaltraining.entity.shoprecord;
import org.example.practicaltraining.mapper.shoprecordMapper;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/shoprecord")
@ResponseBody
public class shoprecordController {
    @Resource
    shoprecordMapper shoprecordMapper;

    //获取购买记录
    @GetMapping("/getshoprecord/{item_id}")
    public Result<?> getshoprecord(@PathVariable("item_id") Integer item_id) {
        LambdaQueryWrapper<shoprecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(shoprecord::getItem_id,item_id);
        return Result.success(shoprecordMapper.selectList(wrapper));
    }

    @GetMapping
    public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "8") Integer pageSize){
        LambdaQueryWrapper<shoprecord> wrappers = Wrappers.<shoprecord>lambdaQuery();
        Page<shoprecord> userPage =shoprecordMapper.selectPage(new Page<>(pageNum,pageSize), wrappers);
        return Result.success(userPage);
    }
}
